package com.wxq.workpad.utils;

import android.content.res.Resources;


import me.jessyan.autosize.AutoSizeConfig;

/**
 * @author ArcherYc
 * @date on 2019-08-20  16:58
 * @mail 247067345@qq.com
 */
public class FontUtils {

    private static float font = -1;

    public static void setScaleFont(Resources resources) {
        float font = getFont();
        if (font != 1) {
            resources.getDisplayMetrics().scaledDensity = AutoSizeConfig.getInstance().getInitDensity() * font;
        }
    }

    public static float getFontScale(){
        return SpUtils.getInstance().getFloat(SpUtilsConfig.currentFontSize, 1f);
    }

    public static int getWebFontScale(){
        return (int) (100* FontUtils.getFontScale());
    }

    public static float getFont() {
        if (font == -1) {
            font = SpUtils.getInstance().getFloat(SpUtilsConfig.currentFontSize, 1f);
        }
        return font;
    }

    public static void setFont(float newFont) {
        SpUtils.getInstance().putFloat(SpUtilsConfig.currentFontSize, newFont);
        font = newFont;
    }

}
